home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / asm_subr.arc / BCDOUT < prev    next >
Encoding:
Text File  |  1985-12-22  |  2.1 KB  |  91 lines

  1. ;-------------------------bcdout routine begins--------------------------+
  2. ; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
  3. ;         page : 66
  4. ;
  5. ; NAME BCDOUT
  6. ; ROUTINE FOR conversion from BCD to ASCII decimal
  7. ;
  8. ; FUNCTION: This routine converts a 36-digit number sstored in BCD form
  9. ; to ASCII decimal form which is sent to the std I/O device.
  10. ;
  11. ; INPUT: Upon entry a 36-digit number is stored in an 18-byte BCD buffer
  12. ; called BCDBUFF in the DATAS data segment.
  13. ;
  14. ; OUTPUT: A string of ASCII digits representing a decimal number is
  15. ; stored in a buffer called TBUFF and then sent out through a standard
  16. ; output device.
  17. ;
  18. ; REGISTERS USED:  No registers are modified.
  19. ; SEGMENTS REFERENCED:  DATAS is a data segment containing BCDBUFF
  20. ; and TBUFF.
  21. ;
  22. ; ROUTINES CALLED:  STDOUT
  23. ; SPECIAL NOTES: None
  24. ;
  25. ; ROUTINE FOR CONVERSION FROM BCD TO ASCII DECIMAL
  26. ;
  27. bcdout    proc    far
  28. ;
  29.     push    ds        ; save registers
  30.     push    si
  31.     push    dx
  32.     push    cx
  33.     push    ax
  34. ;
  35. ; set up a data segment
  36.     mov    ax,datas    ; point to data segment
  37.     mov    ds,ax
  38. ;
  39.     mov    cx,18        ; for a count of 18
  40.     lea    si,bcdbuff    ; point to bcd buffer
  41.     add    si,17        ; point to end of bcd buffer
  42.     mov    dh,0        ; clear flag for leading zeros
  43. ;
  44. bdcout1:
  45.     push    cx        ; save count
  46.     mov    al,[si]        ; get BCD byte
  47.     dec    si        ; and point to next
  48.     mov    dl,al        ; save it
  49. ;
  50. ; upper digit
  51.     mov    cl,4        ; for a count of four
  52.     rol    al,cl        ; rotate byte
  53.     and    al,0Fh        ; just the digit
  54.     or    dh,al        ; leading zeros?
  55.     jz    bcdout2        ; if so skip digit
  56.     add    al,30h        ; make it ASCII
  57.     call    stdout        ; send it
  58. ;
  59. bcdout2:
  60.     pop    cx        ; restore count
  61.     cmp    cx,1        ; last digit ?
  62.     jnz    bcdout3        ; skip if not
  63.     mov    dh,0FFh        ; set flag if so
  64. ;
  65. bcdout3:
  66.     push    cx        ; save count
  67. ;
  68.     mov    al,dl        ; get byte back
  69. ;
  70. ; lower digit
  71.     and    al,0Fh        ; just the digit
  72.     or    dh,al        ; leading zeros?
  73.     jz    bcdout4        ; if so skip digit
  74.     add    al,30h        ; make is ASCII
  75.     call    stdout        ; send it
  76. ;
  77. bcdout4:
  78. ;
  79.     pop    cx        ; restore loop count
  80.     loop    bcdout1
  81. ;
  82.     pop    ax        ; restore registers
  83.     pop    cx
  84.     pop    dx
  85.     pop    si
  86.     pop    ds
  87.     ret            ; return
  88. ;
  89. bcdout    endp
  90. ;-------------------------bcdout routine ends---------------------------+
  91.